package com.tencent.sample;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class Main extends Activity {

	/**
	 * 开发者申请广告时获得的ID
	 */
	private String id = "1";
	
	/**
	 * 是否采用测试模式
	 */
	private boolean testMode = true;
	
	/**
	 * 广告的切换时间
	 */
	private int showTime = 30;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        xmlayoutClick();
        codelayoutClick();
        suslayoutClick();
//        setURLClick();
        setAppIdClick();
        setADTimeClick();
        setTestModeClick();
    }
    
  

    
    private void initApp()
    {
//    	 AdManager.init(id, showTime, testMode);
    	 
    }
    

    
    private void xmlayoutClick() {
    	Button bt = (Button)findViewById(R.id.xmlayout);
    	bt.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v){
				initApp();
				
				Intent intent = new Intent();
				intent.setClass(Main.this, Xmlayout.class);
				startActivity(intent);
			}
		});
    }
    private void codelayoutClick() {
    	Button bt = (Button)findViewById(R.id.codelayout);
    	bt.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v){
				initApp();
				Intent intent = new Intent();
				intent.setClass(Main.this, Codelayout.class);
				startActivity(intent);
			}
		});
    }
    private void suslayoutClick() {
    	Button bt = (Button)findViewById(R.id.suslayout);
    	bt.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v){
				initApp();
				Intent intent = new Intent();
				intent.setClass(Main.this, Suslayout.class);
				startActivity(intent);
			}
		});
    }
    
    
    private void setADTimeClick()
    {
    	final EditText adTime = (EditText)findViewById(R.id.lastTime);
    	adTime.setText(String.valueOf(showTime));
    	
    	Button bt = (Button)findViewById(R.id.lastTimeButton);
    	bt.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v){
				String s = adTime.getText().toString();
				if(!TextUtils.isEmpty(s) && TextUtils.isDigitsOnly(s))
				{
					showTime = Integer.parseInt(s);
				}
				Toast.makeText(getApplicationContext(), "设置时间成功："+showTime,Toast.LENGTH_SHORT).show();
			}
		});
    }
    
    private void setAppIdClick() {
    	final EditText et = (EditText)findViewById(R.id.appid);
    	et.setText(id);
    	Button bt = (Button)findViewById(R.id.sureappid);
    	bt.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v){
				id = et.getText().toString();
				Toast.makeText(getApplicationContext(), "设置appid成功："+ id,Toast.LENGTH_SHORT).show();
			}
		});
    }
    
    private void setTestModeClick()
    {

    	
    	RadioGroup radioGroup = (RadioGroup)findViewById(R.id.testMode);
    	radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.test:
					testMode = true;
					break;
				case R.id.formal:
					testMode = false;
					break;
				default:
					break;
				}
				
			}
		});
    	
    }
}